
package com.ukao.cashregister.pesenter;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.Coupons;
import com.ukao.cashregister.bean.RechargeRecordBean;
import com.ukao.cashregister.bean.TradeRecordBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.ConsumeRecordView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class ConsumeRecordPesenter extends BasePresenter<ConsumeRecordView> {

    public ConsumeRecordPesenter(ConsumeRecordView view) {
        attachView(view);
    }


    /**
     优惠券
     */
    public void couponInfoList (String userId ) {

        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("userId",userId);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.couponInfoList (Constant.createParameter(mHashMap)),
                new ApiCallback<Coupons>() {
                    @Override
                    public void onSuccess(Coupons model) {
                        if (model.getHttpCode()==200){
                            mvpView.loadCouponsData(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.loadload();
                    }

                });
    }



    /**
     用户订单交易流水
     */
    public void tradeOrder (String userId,int pageNum, int pageSize ) {

        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("userId",userId);
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.tradeOrder (Constant.createParameter(mHashMap)),
                new ApiCallback<TradeRecordBean>() {
                    @Override
                    public void onSuccess(TradeRecordBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.loadtradeOrderData(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.loadload();
                    }

                });
    }


    /**
     用户充值流水
     */
    public void userRecharge (String userId,int pageNum, int pageSize  ) {
        HashMap     mHashMap=new HashMap<String,String>();
        mHashMap.put("userId",userId);
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(apiStores.userRecharge (Constant.createParameter(mHashMap)),
                new ApiCallback<RechargeRecordBean>() {
                    @Override
                    public void onSuccess(RechargeRecordBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.loadRechargeData(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.loadload();
                    }

                });
    }


}
